package com.itheima.studenthomework.service;

import com.itheima.studenthomework.dao.UserDao;
import com.itheima.studenthomework.domain.User;

import java.util.ArrayList;

public class UserService {
    public int isExist(String username) {
        int index = -1;
        UserDao userDao = new UserDao();
        ArrayList<User> list = userDao.giveList();
        for (int i = 0; i < list.size(); i++) {
            User user = list.get(i);
            if(username.equals(user.getUsername())){
                index = i;
                break;
            }
        }
        return index;
    }

    public boolean addUser(User user) {
        UserDao userDao = new UserDao();
        boolean flag = userDao.addUser(user);
        return flag;
    }

    public boolean verifyPassword(int index, String password) {
        UserDao userDao = new UserDao();
        boolean flag = userDao.verifyUser(index,password);
        return flag;
    }
}
